package com.stu.controller;

import com.stu.config.websocker.WebSocket;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname WebScoketController
 * @Description TODO websocket
 * @Version 1.0.0
 * @Date 2022/2/14 12:30
 * @Created by yd
 */
@Api(tags = "webSocket")
@Slf4j
@RestController
@RequestMapping("/websocket")
public class WebScoketController {

    @Autowired
    WebSocket webSocket;

    @ApiOperation(value = "群发消息", notes = "群发消息-测试")
    @GetMapping("/sendAllWebSocket")
    public String test() {
        String text = "你们好！这是websocket群体发送！";
        webSocket.sendAllMessage(text);
        return text;
    }

    @ApiOperation(value = "单点发送", notes = "单点发送-测试")
    @GetMapping("/sendOneWebSocket/{userName}")
    public String sendOneWebSocket(@PathVariable("userName") String userName) {
        String text = userName + " 你好！ 这是websocket单人发送！";
        webSocket.sendOneMessage(userName, text);
        return text;
    }
}
